package org.aeon.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author: MissingAeon
 * @date: 2024/1/30 9:24
 * @description:
 */
public class ServerConfig {
    static Properties properties;

    static {
        try (InputStream in = Config.class.getResourceAsStream("/server.properties")) {
            properties = new Properties();
            properties.load(in);
        } catch (IOException e) {
            throw new ExceptionInInitializerError(e);
        }
    }

    public static int getTokenTimeoutSeconds() {
        final String value = properties.getProperty("token.timeoutSeconds");
        final int DEFAULT_VALUE = 60;
        if (value == null) {
            return DEFAULT_VALUE;
        } else {
            try {
                return Integer.parseInt(value);
            } catch (NumberFormatException e) {
                return DEFAULT_VALUE;
            }
        }
    }

    public static int getUserInfoTimeoutSeconds() {
        final String value = properties.getProperty("user.info.timeoutSeconds");
        final int DEFAULT_VALUE = 60;
        if (value == null) {
            return DEFAULT_VALUE;
        } else {
            try {
                return Integer.parseInt(value);
            } catch (NumberFormatException e) {
                return DEFAULT_VALUE;
            }
        }
    }

    public static int getUserAllTimeoutSeconds() {
        final String value = properties.getProperty("user.all.timeoutSeconds");
        final int DEFAULT_VALUE = 60;
        if (value == null) {
            return DEFAULT_VALUE;
        } else {
            try {
                return Integer.parseInt(value);
            } catch (NumberFormatException e) {
                return DEFAULT_VALUE;
            }
        }
    }

    public static double getTokenResetTriggerFactor() {
        final String value = properties.getProperty("token.resetTriggerFactor");
        final double DEFAULT_VALUE = 0.1;
        if (value == null) {
            return DEFAULT_VALUE;
        } else {
            try {
                return Double.parseDouble(value);
            } catch (NumberFormatException e) {
                return DEFAULT_VALUE;
            }
        }
    }
}
